<?php
/**
 * file:OptBusniess.php
 * This file is part of J-Game.
 *
 * @link    https://www.f4soft.com
 * @document https://www.f4soft.com
 * @contact 173120209@qq.com
 * @autho   :jackliang
 */
namespace F4soft\glass;

use F4soft\library\Database;

class OptBusniess {
    private static $instance;
    private static $config = [];
    private static $rediskey = [];

    /**
     * @return \F4soft\glass\OptBusniess
     */
    public static function getInstance() {
        if (self::$instance == null) {
            self::$instance = new self();
        }
        self::$config = require __DIR__ . "/../../conf/datebase.php";
        array_push(self::$rediskey, "gong_" . self::$config['oprgroup'] . '_' . self::$config['serverId'] . '_avatar_rank_opt_' . self::$config['optid']);
        array_push(self::$rediskey, "gong_" . self::$config['oprgroup'] . '_' . self::$config['serverId'] . '_avatar_rank_opt_' . self::$config['optid'] . '_end');
        array_push(self::$rediskey, "gong_" . self::$config['oprgroup'] . '_' . self::$config['serverId'] . '_avatar_rank_opt_' . self::$config['optid'] . '_start');
        return self::$instance;
    }

    public function main() {
        ini_set("memory_limit", "1024M");
        $userIds = Database::getInstance()->select("AvatarModel", ["roleName", "uid"], ["lastLoginT[<=]" => 1584633600000]);
        echo "userIds is " . json_encode($userIds) . PHP_EOL;
        foreach (self::$rediskey as $v) {
            echo "key=" . $v . PHP_EOL;
            foreach ($userIds as $k => $item) {
                echo "del redis userIds is " . json_encode($item['roleName']) . PHP_EOL;
                Database::getRedis()->zRem($v, $item['uid']);
            }
        }
    }
}